package com.ruoyi.system.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.EmploymentStatusVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EmploymentInfo;
import com.ruoyi.system.service.IEmploymentInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 就业信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-05
 */
@RestController
@RequestMapping("/system/EmploymentInfo")
public class EmploymentInfoController extends BaseController
{
    @Autowired
    private IEmploymentInfoService employmentInfoService;

    /**
     * 查询就业信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(
            @RequestParam(required = false) Long uid,
            EmploymentInfo employmentInfo
    )
    {
        startPage();
        List<EmploymentInfo> list = employmentInfoService.selectEmploymentInfoList(employmentInfo,uid);
        return getDataTable(list);
    }

    /**
     * 导出就业信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:export')")
    @Log(title = "就业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export/{uid}")
    public void export(HttpServletResponse response, EmploymentInfo employmentInfo,@PathVariable Long uid)
    {
        System.out.println(uid);
        List<EmploymentInfo> list = employmentInfoService.selectEmploymentInfoList(employmentInfo,uid);
        ExcelUtil<EmploymentInfo> util = new ExcelUtil<EmploymentInfo>(EmploymentInfo.class);
        util.exportExcel(response, list, "就业信息数据");
    }

    /**
     * 获取就业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(employmentInfoService.selectEmploymentInfoById(id));
    }

    /**
     * 新增就业信息
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:add')")
    @Log(title = "就业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmploymentInfo employmentInfo)
    {
        return toAjax(employmentInfoService.insertEmploymentInfo(employmentInfo));
    }

    /**
     * 修改就业信息
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:edit')")
    @Log(title = "就业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmploymentInfo employmentInfo)
    {
        return toAjax(employmentInfoService.updateEmploymentInfo(employmentInfo));
    }

    /**
     * 删除就业信息
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:remove')")
    @Log(title = "就业信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(employmentInfoService.deleteEmploymentInfoByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:list')")
    @GetMapping("/countEmploymentStatus")
    public TableDataInfo countEmploymentStatus()
    {
        List<EmploymentStatusVO> list = employmentInfoService.countByEmploymentStatus();
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:list')")
    @GetMapping("/countEmploymentIntent")
    public TableDataInfo countEmploymentIntent()
    {
        List<EmploymentStatusVO> list = employmentInfoService.countByEmploymentIntent();
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:list')")
    @GetMapping("/countEmploymentProvince")
    public TableDataInfo countEmploymentProvince()
    {
        List<EmploymentStatusVO> list = employmentInfoService.countByEmploymentProvince();
        return getDataTable(list);
    }

    /**
     * 获取就业信息统计信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:list')")
    @GetMapping("/getEmploymentStats")
    public TableDataInfo getEmploymentStats() {
        List<Map<String, Object>> list = employmentInfoService.getEmploymentStats();
        return getDataTable(list);
    }

    /**
     * 获取就业省份统计信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:EmploymentInfo:list')")
    @GetMapping("/countEmploymentProvinceByGrade")
    public TableDataInfo getProvinceStats() {
        List<Map<String, Object>> list = employmentInfoService.getProvinceStats();
        return getDataTable(list);
    }
}
